<?php

class Form_Admin_Link extends Form_Upload
{
    /**
     * 创建 Form_Admin_Link 表单对象
     *
     * @param string $action
     * @param string $status
     *
     * @return Form_Admin_Link
     */
    static function createForm($action, $status = 'create')
    {
        $form = self::_createFromConfig($action, 'link_form.yaml');
        if ($status == 'edit')
        {
        }

        return $form;
    }

    /**
     * 从配置文件创建表单
     *
     * @param string $action
     * @param string $config_name
     *
     * @return Form_Admin_Link
     */
    static protected function _createFromConfig($action, $config_name)
    {
        $form = new Form_Admin_Link('form_admin_link', $action);
        $filename = rtrim(dirname(__FILE__), '/\\') . DS . $config_name;
        $form->loadFromConfig(Helper_YAML::loadCached($filename));
        $form->addValidations(Link::meta());
        $form['logo_filename']->dir = Q::ini('appini/links/img_dir');

        $types = Q::normalize(Q::ini('appini/links/upload_allowed_types'));
        $size = intval(Q::ini('appini/links/upload_allowed_size') * 1024);
        $dim = Q::ini('appini/links/logo_pic_width') . 'x' . Q::ini('appini/links/logo_pic_height');
        $form['postfile']->_tips = sprintf($form['postfile']->_tips, implode('/', $types), $size / 1024, $dim);
        $form->selectUploadElement('postfile')
             ->uploadAllowedTypes($types)
             ->uploadAllowedSize($size)
             ->enableSkipUpload();
        return $form;
    }
}

